package com.ruoyi.merchandise.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchandise.domain.TbOrderinfo;
import com.ruoyi.merchandise.service.ITbOrderinfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订购信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-21
 */
@RestController
@RequestMapping("/merchandise/orderInfo")
public class TbOrderinfoController extends BaseController
{
    @Autowired
    private ITbOrderinfoService tbOrderinfoService;

    /**
     * 查询订购信息列表
     */
    @PreAuthorize("@ss.hasPermi('merchandise:orderInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbOrderinfo tbOrderinfo)
    {
        startPage();
        List<TbOrderinfo> list = tbOrderinfoService.selectTbOrderinfoList(tbOrderinfo);
        return getDataTable(list);
    }

    /**
     * 导出订购信息列表
     */
    @PreAuthorize("@ss.hasPermi('merchandise:orderInfo:export')")
    @Log(title = "订购信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbOrderinfo tbOrderinfo)
    {
        List<TbOrderinfo> list = tbOrderinfoService.selectTbOrderinfoList(tbOrderinfo);
        ExcelUtil<TbOrderinfo> util = new ExcelUtil<TbOrderinfo>(TbOrderinfo.class);
        util.exportExcel(response, list, "订购信息数据");
    }

    /**
     * 获取订购信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchandise:orderInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbOrderinfoService.selectTbOrderinfoById(id));
    }

    /**
     * 新增订购信息
     */
    @PreAuthorize("@ss.hasPermi('merchandise:orderInfo:add')")
    @Log(title = "订购信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbOrderinfo tbOrderinfo)
    {
        return toAjax(tbOrderinfoService.insertTbOrderinfo(tbOrderinfo));
    }

    /**
     * 修改订购信息
     */
    @PreAuthorize("@ss.hasPermi('merchandise:orderInfo:edit')")
    @Log(title = "订购信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbOrderinfo tbOrderinfo)
    {
        if(tbOrderinfo.getCloseStatus().equals("0")){
            tbOrderinfo.setCloseTime(new Date());
        }
        return toAjax(tbOrderinfoService.updateTbOrderinfo(tbOrderinfo));
    }

    /**
     * 删除订购信息
     */
    @PreAuthorize("@ss.hasPermi('merchandise:orderInfo:remove')")
    @Log(title = "订购信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbOrderinfoService.deleteTbOrderinfoByIds(ids));
    }
}
